//
//  WHStatusViewModel.swift
//  8.31-WH微博
//
//  Created by 吴涵 on 15/9/10.
//  Copyright © 2015年 wuhan. All rights reserved.
//

import UIKit
import ReactiveCocoa

class WHStatusViewModel: NSObject {
    
    var statuses: [AnyObject] = [WHUserStatusModel]()
    
    func loadStatus() -> RACSignal {
        
        return RACSignal.createSignal({ [weak self] (subscriber) -> RACDisposable! in
            
            WHWebTools.sharedTools.loadStatus().subscribeNext({ (result) -> Void in
                guard let array = result["statuses"] as?[[String: AnyObject]] else {
                    printLog("没有正确的数据")
                    return
                }

                for dict in array {
                self?.statuses.append(WHUserStatusModel(status: WHStatus(dict: dict)))
                }
                subscriber.sendCompleted()
                }, error: { (err) -> Void in
                     subscriber.sendError(err)
                }) { () -> Void in
                    printLog("微博数据加载完成")
            }
            

            return nil
        })
        
    }
    

}
